<?php

/*
 *  this is the main component; it returns an adequate entry list for a search query (JSON)
 *
 */


include_once "file.php";
include_once "sql.php";
include_once "to_index.php";
include_once "get_item.php";

header("Access-Control-Allow-Origin: *");


sqlInit();
$data = search( get_img_file(), 0 );


$start = isset( $_GET["start"] ) ? (
  is_numeric( $_GET["start"] ) ?
    $_GET["start"] : $start
) : 0;

$data = array_slice($data, $start, 10);

foreach($data as $k => $v){
  $data[$k] = get_item($k);
  $data[$k]["score"] = $v;
}
sqlClose();

echo json_encode($data);

?>
